local shijie = fk.CreateSkill {
  name = "th_shijie",
}

shijie:addEffect(fk.EventPhaseProceeding, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target ~= player and target.phase == Player.Start and player:hasSkill(shijie.name) and
    player:compareDistance(target, player:getMark("@sakuya_shi") - 1, "<=")
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = shijie.name,
      prompt = "#th_shijie-invoke:::"..(player:distanceTo(target) + 1)
    })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, shijie.name, "offensive")
    local x = player:distanceTo(target) + 1
    room:addPlayerMark(player, "@sakuya_shi", x * -1)
    player:drawCards(2, shijie.name)
    room:askToPlayCard(player, {
      skill_name = shijie.name,
      prompt = "#th_shijie-use",
      extra_data = { bypass_times = true, bypass_distances = true }
    })
  end,
})
shijie:addEffect(fk.TurnEnd, {
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(shijie.name) and
    player:getMark("@sakuya_shi") < 4
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:notifySkillInvoked(player, shijie.name, "control")
    player.room:addPlayerMark(player, "@sakuya_shi", 1)
  end,
})

Fk:loadTranslationTable{
  ["th_shijie"] = "世界",
  [":th_shijie"] = "每名角色回合结束时，你获得一枚“时”（至多4枚）；其他角色的准备阶段，你可以弃置X枚“时”，摸两张牌并可使用一张牌（无距离限制）（X为你与其的距离+1）。",

  ["#th_shijie-invoke"] = "世界：你可弃置%arg枚“时”以发动此技能",
  ["#th_shijie-use"] = "世界：你可使用其中一张牌。",
  ["@sakuya_shi"] = "时",
}

return shijie